package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCarMilesVo;
import com.bdmc.report.domain.bo.ReportCarMilesBo;
import com.bdmc.report.service.IReportCarMilesService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 车辆里程统计控制器
 *
 * @author bdmc
 * @date 2022-08-10
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/carMiles")
public class ReportCarMilesController extends BaseController {

    private final IReportCarMilesService iReportCarMilesService;

    /**
     * 查询车辆里程统计列表
     */
    @SaCheckPermission("report:carMiles:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCarMilesVo> list(@Validated(QueryGroup.class) ReportCarMilesBo bo, PageQuery pageQuery) {
        return iReportCarMilesService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出车辆里程统计列表
     */
    @SaCheckPermission("report:carMiles:export")
    @Log(title = "车辆里程统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCarMilesBo bo, HttpServletResponse response) {
        List<ReportCarMilesVo> list = iReportCarMilesService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆里程统计", ReportCarMilesVo.class, response);
    }

    /**
     * 获取车辆里程统计详细信息
     */
    @SaCheckPermission("report:carMiles:query")
    @GetMapping("/{milesId}")
    public AjaxResult<ReportCarMilesVo> getInfo(@PathVariable("milesId") Long milesId) {
        return AjaxResult.success(iReportCarMilesService.queryById(milesId));
    }

    /**
     * 新增车辆里程统计
     */
    @SaCheckPermission("report:carMiles:add")
    @Log(title = "车辆里程统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCarMilesBo bo) {
        return toAjax(iReportCarMilesService.insertByBo(bo));
    }

    /**
     * 修改车辆里程统计
     */
    @SaCheckPermission("report:carMiles:edit")
    @Log(title = "车辆里程统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCarMilesBo bo) {
        return toAjax(iReportCarMilesService.updateByBo(bo));
    }

    /**
     * 删除车辆里程统计
     */
    @SaCheckPermission("report:carMiles:remove")
    @Log(title = "车辆里程统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{milesIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] milesIds) {
        return toAjax(iReportCarMilesService.deleteWithValidByIds(Arrays.asList(milesIds), true));
    }
}
